package com.dhcc.bpm.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.system.entity.Param;
import com.dhcc.bpm.modules.system.service.IParamService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;
/**
 * @ClassName ParamController
 * @Description 参数管理 控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/param")
@Api(value = "参数管理", tags = "参数管理")
public class ParamController extends BladeController {

	private IParamService paramService;

	/**
	 * @Description 详情
	 * @Author sjm
	 * @Date 10:06 2020/2/22 0022
	 * @param param
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.system.entity.Param>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入param")
	@ApiLog("查询参数详情")
	@Log(title = "查询参数详情", businessType = BusinessType.SELECT)
	public R<Param> detail(Param param) {
		Param detail = paramService.getOne(Condition.getQueryWrapper(param));
		return R.data(detail);
	}

	/**
	 * @Description 分页
	 * @Author sjm
	 * @Date 10:06 2020/2/22 0022
	 * @param param
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.system.entity.Param>>
	 **/
	@GetMapping("/list")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "paramName", value = "参数名称", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "paramKey", value = "参数键名", paramType = "query", dataType = "string"),
			@ApiImplicitParam(name = "paramValue", value = "参数键值", paramType = "query", dataType = "string")
	})
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入param")
	@ApiLog("查询参数列表")
	@Log(title = "查询参数列表", businessType = BusinessType.SELECT)
	public R<IPage<Param>> list(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
		IPage<Param> pages = paramService.page(Condition.getPage(query), Condition.getQueryWrapper(param, Param.class));
		return R.data(pages);
	}

	/**
	 * @Description 新增或修改
	 * @Author sjm
	 * @Date 10:06 2020/2/22 0022
	 * @param param
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "新增或修改", notes = "传入param")
	@ApiLog("新增或修改参数")
	@Log(title = "参数", businessType = BusinessType.INSERT)
	public R submit(@Valid @RequestBody Param param) {
		return R.status(paramService.saveOrUpdate(param));
	}


	/**
	 * @Description 删除
	 * @Author sjm
	 * @Date 10:06 2020/2/22 0022
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	@ApiLog("删除参数")
	@Log(title = "参数", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(paramService.deleteLogic(Func.toLongList(ids)));
	}


}
